if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_reviewIEBill]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_reviewIEBill]
GO
CREATE PROC sp_reviewIEBill
	@id				int,
	@status			int,
	@reason			nvarchar(200),
	@approvedID		int,
	@orderID		int
AS
BEGIN
	DECLARE @date datetime
		SELECT @date=getDate()
	DECLARE @cusID int
		SELECT @cusID = AccountID  FROM OrderRequest WHERE ID=@orderID
	DECLARE @amount varchar(20)

	UPDATE ImportExportBills SET
		Status = @status,
		RejectReason = @reason,
		ApprovedByUser = @approvedID,
		LastUpdate = @date
		WHERE ID = @id
	IF(@status = 1)
		BEGIN
			UPDATE OrderRequest SET Status = 3 WHERE ID = @orderID
		END
	SELECT @amount = CAST((SUM(CAST(TotalPrice AS FLOAT)))AS varchar(20)) 
		FROM ImportExportBills WHERE CustomerID = @cusID AND Status = 1
	IF(@amount >= 1000)
		BEGIN
			UPDATE Account SET AccountType = 2 WHERE ID = @cusID
		END
END